const mongoose = require('mongoose')

const Schema = mongoose.Schema

const schema = new Schema({
  // 编码
  code: String,
  // 现货还是合约,1现货、2合约
  market: Number,
  // 操作归类,buy,sell,pinDuo,pingKong,
  type: String,
  // 原因,英文key
  reason: String,
  orderId: String,
  // 杠杆
  leverage: Number,
  // 数量
  quantity: Number,
  usdt: {
    type: Number,
    default: 0
  },
  price: Number,
  // 是不是追加0,1
  append: {
    type: Number,
    default: 0
  },
  before_quantity: {
    type: Number,
    default: 0
  },
  // 被平仓部分的数量
  ping_quantity: {
    type: Number,
    default: 0
  },
  // 合并开仓平仓的
  commission: {
    type: Number,
    default: 0
  },
  // 手续费单向
  commission_one_way: {
    type: Number,
    default: 0
  },
  // 合并开仓平仓的保证金
  commission_margin: {
    type: Number,
    default: 0
  },
  income: {
    type: Number,
    default: 0
  },
  income_rate: {
    type: Number,
    default: 0
  },
  // 扣除手续费后的
  income_result: {
    type: Number,
    default: 0
  },
  commission_margin_result: {
    type: Number,
    default: 0
  },
  // 扣除手续费后的
  income_rate_result: {
    type: Number,
    default: 0
  },
  income_res_quantity: {
    type: Number,
    default: -1
  },
  keep_days: {
    type: Number,
    default: 0
  },
  add_times: {
    type: Number,
    default: 0
  },
  lastType: String,
  lastReason: String,
  lastId: String,
  // 使用策略
  strategy: {
    type: String,
    default: ''
  },
  strategy_result: {
    type: String,
    default: ''
  },
  last_strategy: {
    type: String,
    default: ''
  },
  last_strategy_result: {
    type: String,
    default: ''
  },
  price_change_percent: {
    type: Number,
    default: 0
  },
  // 成交
  quote_volume: {
    type: Number,
    default: 0
  },
  // 详情
  detail: {
    type: Object,
    default: {}
  },
  track_list: {
    type: Array,
    default: []
  },
  // 是否亏损多
  loss_many: {
    type: Number,
    default: 0
  },
  // 覆盖原因
  no_cover_reason: {
    type: Number,
    default: 0
  },
  create_at: {
    type: Date,
    default: Date.now
  }
})

module.exports = mongoose.model('ExecuteRecord', schema)
